home *** CD-ROM | disk | FTP | other *** search
/ Click Press Kit / Click Press Kit.iso / mac / QuickTime704.pkg / Contents / Resources / deleteomatic < prev    next >
Encoding:
Text File  |  2005-03-16  |  894 b   |  52 lines

  1. #!/usr/bin/perl
  2.  
  3. my $ROOT_DIR = $ARGV[0];
  4. my $DATA_FILE = $ARGV[1];
  5.  
  6. open (FILE, $DATA_FILE) || die ;
  7.  
  8. while (defined ($deleteme = <FILE>)) {
  9.     chomp $deleteme;
  10. #    system("/bin/rm -rf \"" . $ROOT_DIR . $deleteme . "\"");
  11.     if (length($deleteme) > 0)
  12.     {
  13.         deleteTree($ROOT_DIR . $deleteme);
  14.     }
  15. }
  16.  
  17. sub deleteTree
  18. {
  19.     my $path            = $_[0];
  20.  
  21.     if (-e $path){
  22.         if (-d $path){
  23.             if (!-l $path){
  24.  
  25.                 local* THEDIR;
  26.                    my $file;
  27.  
  28.                 opendir THEDIR, $path;
  29.  
  30.                 while ($file = readdir THEDIR){
  31.                     if ($file ne '.' && $file ne '..'){
  32.                         deleteTree($path . "/" . $file);
  33.                     }
  34.                 }
  35.  
  36.                 closedir THEDIR;
  37.  
  38.                    rmdir $path;
  39.             } else {
  40.             unlink $path;
  41.             }
  42.         } else {
  43.             unlink $path;
  44.         }
  45.     } else {
  46.         if (-l $path)
  47.         {
  48.             unlink $path;
  49.         }
  50.     }
  51. }
  52.